import {Button, DatePicker, Form, Input, Select} from "antd";
import React, {useState} from 'react';
import {useNavigate} from 'react-router-dom';
import moment from "moment";
import store from "../../../store";
const {Option} = Select;
const AddMarketing=()=>{
    const [validityTime, setValidityTime]=useState()
    const [form] = Form.useForm();
    const navigate = useNavigate();
    const onReset = () => {
        navigate(-1)
    };
    const submit = (values) => {
        console.log("111",values)

    };

    // 编辑表单提交
    const onFinish = (values) => {
        values.validityTime=validityTime
        console.log('Success:', values);
        let arr={
            operationTime:values.validityTime,
            operationName:values.operationName,
            marketingType:values.marketingType,
            marketingDetails:values.marketingDetails,
            status:values.status
        }
        store.market.count.push(arr)
        navigate('/home/HuiManagement')
    };
    //时间选择器的数据处理
    const range = (start, end) => {
        const result = [];
        for (let i = start; i < end; i++) {
            result.push(i);
        }
        return result;
    };

    const disabledDate = (current) => {
        // Can not select days before today and today
        return current && current < moment().endOf('day');
    };
    const disabledDateTime = () => ({
        disabledHours: () => range(0, 24).splice(4, 20),
        disabledMinutes: () => range(30, 60),
        disabledSeconds: () => [55, 56],
    });

    const onChange = (value, dateString) => {
        console.log('Selected Time: ', value);
        console.log('Formatted Selected Time: ', dateString);
    };
    const onOk = (value) => {
        console.log('onOk: ', value);
    };
    return <div>
        <h1>新增</h1>
        <Form
            labelCol={{
                span: 4,
            }}
            wrapperCol={{
                span: 14,
            }}
            layout="horizontal"
            onFinish={onFinish}
        >
            <Form.Item label="操作时间">
                <DatePicker
                    format="YYYY-MM-DD HH:mm:ss"
                    disabledDate={disabledDate}
                    disabledTime={disabledDateTime}
                    onChange={(moment, string)=>{
                        console.log(string)
                        setValidityTime(string)
                    }}
                    style={{width: '280px'}} />
            </Form.Item>
            <Form.Item label="操作人" name="operationName">
                <Input className={'inputBox'}/>
            </Form.Item>
            <Form.Item label="营销类型" name="marketingType">
                <Input className={'inputBox'}/>
            </Form.Item>
            <Form.Item label="营销详情" name="marketingDetails">
                <Input className={'inputBox'}/>
            </Form.Item>
            <Form.Item label="状态" name="status">
                <Select
                    allowClear
                    style={{width: '280px'}}
                >
                    <Option value="推送中">推送中</Option>
                    <Option value="已完成">已完成</Option>
                    <Option value="待执行">待执行</Option>
                </Select>
            </Form.Item>
            <Form.Item className={'buttonStyle'}>
                <Button className={'buttonBox'} htmlType="submit" onClick={submit}>
                    保存
                </Button>
                <Button htmlType="button" onClick={onReset}>
                    取消
                </Button>
            </Form.Item>
        </Form>
    </div>
}
export default AddMarketing;